import org.junit.Test;
import test.ListNode;

/**
 * 4  给定链表的头节点，head,请反转链表
 */
public class reverseList {

    @Test
    public void clibe() {
        ListNode list1 = new ListNode(1, new ListNode(2));
        System.out.println(test1(list1));
    }

    public ListNode test1(ListNode head) {
        ListNode preNode = null;
        ListNode curr = head;
        while (curr !=null){
            ListNode next = curr.getNext();
            curr.setNext(preNode);
            preNode = curr;
            curr = next;
        }
        return preNode;
    }
}
